package com.jack.student.dao;

import com.jack.student.entity.Student;

import java.sql.SQLException;
import java.sql.SQLRecoverableException;
import java.util.Date;
import java.util.List;

public class StudentDao extends BaseDao<Student> {

    //  不用这么登录，直接比对固定的用户名和密码即可
  /*  public Student findStudentByUsernameAndPwd(String username,String pwd){
        String sql = "select * from stus where username =? and pwd = ?"
        this.getBean(Student.class,sql,username,pwd)
    }*/

    //统计学生人数
    public Object stuCount() throws SQLException {
        String sql = "select count(*) from stus";
        Object value =  this.getSingleValue(sql, null);
        return value;

    }

    //查询学生名单
    public List<Student> findAll() throws SQLException {
        String sql = "select * from stus";
        List<Student> studentList = this.getBeanList(Student.class, sql, null);
        return studentList;
    }

    //按照学号查询学生姓名
    public String findNameByID(String id) throws SQLException {
        String sql = "select name from stus where id = ?";
        String value = (String) this.getSingleValue(sql, id);
        return value;
    }

    //按照学生姓名查询学生信息
    public Student findOneByName(String name) throws SQLException {
        String sql = "select * from stus where name  = ?";
        Student student = this.getBean(Student.class, sql, name);
        return student;
    }

    //修改学生出生日期
    public int  updateStuBirthday(Date date) throws SQLException {
        String sql = "update stus set birthday = ? where name = ?";
        int index = this.update(sql, date);
        return index;
    }

    //删除学生记录
    public int deleteStuByName(String name) throws SQLException {
        String sql = "delete from stus where name = ?";
        int index = this.update(sql, name);
        return index;

    }





}
